<template>
  <div class="GNotificationList">
    <filterPanel filterName="GNotificationListFilter" filterTitle="消息通知查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GNotificationListTable" :tableLoading="loading" tableTitle="消息通知列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button @click="add" type="primary">新增</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	export default {
		name: "GNotificationList",
		props: {},
		data() {
			return {
				filterData: [
					{
						title: '标题',
						name: 'title',
						type: 'input',
						value: '',
						maxlength: '200',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布对象',
						name: 'target',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '物流企业', value: 'logistics_enterprise'},
							{label: '合作站点', value: 'cooperative_site'},
							{label: '揽件端', value: 'pull_end'},
							{label: '寄件端', value: 'sender_side'},
							{label: '监管民警', value: 'police'},
							{label: '监管辖区', value: 'regulatory'},
							{label: '公安web端', value: 'security'},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布人',
						name: 'release_user_name',
						type: 'input',
						value: '',
						maxlength: '10',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布状态',
						name: 'status',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '待发布', value: '0'},
							{label: '正在发布', value: '1'},
							{label: '已发布', value: '2'},
							{label: '取消发布', value: '3'},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布时间',
						name: 'time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
					{
						title: '创建时间',
						name: 'create_time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					title: '',
					target: '',
					release_user_name: '',
					status: '',
					time: [],
					create_time: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '标题',
						width: 220,
						name: 'title',
						showTooltip: true,
						isShow: true,
						isSelected: true
					},
					{
						title: '发布对象',
						width: 120,
						name: 'target_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布时间',
						width: 180,
						name: 'release_time_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布人',
						width: 120,
						name: 'release_user_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布状态',
						width: 130,
						name: 'status_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '创建时间',
						width: 180,
						name: 'created_time_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 200,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'detail',
								name: '查看'
							},
							{
								type: 'edit',
								name: '编辑'
							},
							{
								type: 'delete',
								name: '删除',
								btnType: 'danger'
							},
							{
								type: 'cancel',
								name: '取消发布',
								btnType: 'warring'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
			};
		},
		computed: {
			postData() {
				let data = {
					title: this.form.title,
					target: this.form.target,
					release_user_name: this.form.release_user_name,
					status: this.form.status,
					type: '',
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.time && this.form.time.length > 0) {
					data.start_time = this.form.time[0] / 1000;
					data.end_time = this.form.time[1] / 1000;
				}
				if (this.form.create_time && this.form.create_time.length > 0) {
					data.start_time = this.form.time[0] / 1000;
					data.end_time = this.form.time[1] / 1000;
				}
				return data;
			},
		},
		watch: {},
		components: {},
		methods: {
			add() {
				// /notification_list/notification_detail
				this.$toRoutePath({
					path: "/notification_list/notification_detail",
					edit: true,
					query: {type:'add'}
				});
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.$axios.post(this.$api.g_getInformationList, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.release_time_desc = item.release_start_time_desc && item.release_end_time_desc ? `${item.release_start_time_desc}~${item.release_end_time_desc}` : ''
							item.cancel = item.status==1;
							item.detail = true;
							item.edit = item.status==0;
							item.delete = item.status==0;
							return item;
						});
						this.total = data.pagination.total_count || 0;
					} else {
						this.total = 0
						this.tableData = [];
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				switch (type) {
					case 'cancel':
						this.toCancel(data.message_id)
						break;
					case 'detail':
						this.toLook(data.message_id)
						break;
					case 'edit':
						this.toEdit(data.message_id)
						break;
					case 'delete':
						this.toDelete(data.message_id)
						break;
				}
			},
      toEdit(message_id){
	      this.$toRoutePath({
		      path: "/notification_list/notification_detail",
		      edit: true,
		      query: {type:'edit',message_id}
	      });
      },
			toLook(message_id) {
				this.$toRoutePath({
					path: "/notification_list/notification_detail",
					edit: true,
					query: {type:'detail',message_id}
				});
			},
      toDelete(message_id){
	      this.$confirm("此操作将删除该消息, 是否继续?", "提示", {
		      confirmButtonText: "确定",
		      cancelButtonText: "取消",
		      type: "warning",
		      customClass: 'message',
	      }).then(() => {
		      this.$axios.post(this.$api.g_delInformation, {message_id}).then(res => {
			      let {code, msg, data} = res;
			      this.loading = false;
			      if (code == 200) {
				      this.$message.success('删除成功！')
				      this.getData()
			      } else {
				      this.$message.error(msg);
			      }
		      }).catch(ret => {
			      this.$message.error(ret.msg || '服务繁忙，请稍后再试');
		      });
	      }).catch(() => {
		      this.$message({type: "info", message: "已取消"});
	      });
      },
      toCancel(message_id){
	      this.$confirm("此操作将取消发布该消息, 是否继续?", "提示", {
		      confirmButtonText: "确定",
		      cancelButtonText: "取消",
		      type: "warning",
		      customClass: 'message',
	      }).then(() => {
		      this.$axios.post(this.$api.g_saveInformation, {message_id,status:3}).then(res => {
			      let {code, msg, data} = res;
			      this.loading = false;
			      if (code == 200) {
				      this.$message.success('取消发布成功！')
              this.getData()
			      } else {
				      this.$message.error(msg);
			      }
		      }).catch(ret => {
			      this.$message.error(ret.msg || '服务繁忙，请稍后再试');
		      });
	      }).catch(() => {
		      this.$message({type: "info", message: "已取消"});
	      });
      },
		},
		mounted() {
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/infoInteractionManage/notificationList/index.less">

</style>
